package com.kykj.kykj.service.impl;

import com.kykj.kykj.dao.AdminRoleDao;
import com.kykj.kykj.entity.RoleViewEntity;
import com.kykj.kykj.entity.UserRoleViewEntity;
import com.kykj.kykj.service.AdminRoleService;
import com.kykj.kykj.service.RoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminRoleServiceImpl implements AdminRoleService {
    @Resource
    AdminRoleDao adminRoleDao;

    /**
     * 获取列表
     * @param rolename 角色名
     * @param routename 路径名
     * @param start 开始位置
     * @param limit 每页行数
     * @return List
     */
    @Override
    public List<RoleViewEntity> getRoleViewList(String rolename, String routename, int start, int limit) {
        if(!rolename.equals("")){
            rolename = "%"+rolename+"%";
        }
        if(!routename.equals("")){
            routename = "%"+routename+"%";
        }
        return adminRoleDao.getRoleViewList(rolename, routename, start, limit);
    }

    /**
     * 获取总数(按条件）
     * @param rolename 角色名
     * @param routename 路径名
     * @return int:总数
     */
    @Override
    public int getRoleViewListCountByName(String rolename, String routename) {
        if(!rolename.equals("")){
            rolename = "%"+rolename+"%";
        }
        if(!routename.equals("")){
            routename = "%"+routename+"%";
        }
        return adminRoleDao.getRoleViewListCountByName(rolename, routename);
    }

    /**
     * 获取总数
     * @return int:总数
     */
    @Override
    public int getRoleViewCount() {
        return adminRoleDao.getRoleViewCount();
    }

    /**
     * 获取用户角色列表
     * @param uname 用户名
     * @param start 开始位置
     * @param limit 每页行数
     * @return List
     */
    @Override
    public List<UserRoleViewEntity> getUserRoleViewList(String uname, int start, int limit) {
        if(!uname.equals("")){
            uname="%"+uname+"%";
        }
        return adminRoleDao.getUserRoleViewList(uname,start,limit);
    }

    /**
     * 按条件查询（返回数量）
     * @param uname 用户名
     * @return int
     */
    @Override
    public int getUserRoleViewListCountByName(String uname) {
        if(!uname.equals("")){
            uname="%"+uname+"%";
        }
        return adminRoleDao.getUserRoleViewListCountByName(uname);
    }

    /**
     * 返回总数
     * @return int
     */
    @Override
    public int getUserRoleViewListCount() {
        return adminRoleDao.getUserRoleViewListCount();
    }
}
